function keyDown(evt) {
    OurGame.keys[evt.keyCode] = true;
}

function keyUp(evt) {
    OurGame.keys[evt.keyCode] = false;
    OurGame.keyLock[evt.keyCode] = false;
}

function updateGameSelecionKeys() {

    if (GameModeSelectionKEYS.NUM1 in OurGame.keys && OurGame.keys[GameModeSelectionKEYS.NUM1] && !OurGame.gameModeSelected){
        gameModeSelectionEndActivities();
        initTwoPlayerGame();
    }
    if (GameModeSelectionKEYS.NUM2 in OurGame.keys && OurGame.keys[GameModeSelectionKEYS.NUM2] && !OurGame.gameModeSelected){
        gameModeSelectionEndActivities();
        initOnePlayerGame();
    }
    if (GameModeSelectionKEYS.NUM3 in OurGame.keys && OurGame.keys[GameModeSelectionKEYS.NUM3] && !OurGame.gameModeSelected){
        gameModeSelectionEndActivities();
    }
}

function updateArrowKeys(player) {
    if (player.assingedKeys == KeyBoardType.ARROWS) {
        updateARROWS(player);
    }

    if (player.assingedKeys == KeyBoardType.WASD) {
        updateWASD(player);
    }

}
function updateARROWS(player) {

    if (ArrowKeysEnums.DOWN in OurGame.keys && OurGame.keys[ArrowKeysEnums.DOWN]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX(), player.getPosY() + 1)) {
                player.moveY(1);
                if(player.id == OurGame.UID){makeMove(player);}
            }
        }
    }

    if (ArrowKeysEnums.LEFT in OurGame.keys && OurGame.keys[ArrowKeysEnums.LEFT]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX() - 1, player.getPosY())) {
                player.moveX(-1);
                if(player.id == OurGame.UID){makeMove(player);}
            }
        }
    }

    if (ArrowKeysEnums.RIGHT in OurGame.keys && OurGame.keys[ArrowKeysEnums.RIGHT]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX() + 1, player.getPosY())) {
                player.moveX(1);
                if(player.id == OurGame.UID){makeMove(player);}
            }
        }
    }

    if (ArrowKeysEnums.UP in OurGame.keys && OurGame.keys[ArrowKeysEnums.UP]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX(), player.getPosY() - 1)) {
                player.moveY(-1);
                if(player.id == OurGame.UID){makeMove(player);}
            }
        }
    }

    if (ArrowKeysEnums.PLANT in OurGame.keys && OurGame.keys[ArrowKeysEnums.PLANT] && !OurGame.keyLock[ArrowKeysEnums.PLANT]) {
        OurGame.keyLock[ArrowKeysEnums.PLANT] = true;
        if (player.getActiveBombsCount() < player.maxBombsNumber) {
            player.plantBomb();
            if(player.id == OurGame.UID) {plantBomb(player)}
        }
    }
}

function updateWASD(player) {
    if (WASDEnums.DOWN in OurGame.keys && OurGame.keys[WASDEnums.DOWN]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX(), player.getPosY() + 1)) {
                player.moveY(1);

            }
        }
    }

    if (WASDEnums.LEFT in OurGame.keys && OurGame.keys[WASDEnums.LEFT]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX() - 1, player.getPosY())) {
                player.moveX(-1);

            }
        }
    }

    if (WASDEnums.RIGHT in OurGame.keys && OurGame.keys[WASDEnums.RIGHT]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX() + 1, player.getPosY())) {
                player.moveX(1);

            }
        }
    }

    if (WASDEnums.UP in OurGame.keys && OurGame.keys[WASDEnums.UP]){
        if (!player.isMoving()){
            if (isPlaceFree(player.getPosX(), player.getPosY() - 1)) {
                player.moveY(-1);

            }
        }
    }
    
    if (WASDEnums.PLANT in OurGame.keys && OurGame.keys[WASDEnums.PLANT] && !OurGame.keyLock[WASDEnums.PLANT]){
        OurGame.keyLock[WASDEnums.PLANT] = true;
        if (player.getActiveBombsCount() != player.maxBombsNumber) {
        	player.plantBomb();
        }
    }
}
